<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/* application/hooks/LogQueryHook.php */
/**
 *
 * @author vitalify
 *
 */
class LogQueryHook {

	function log_queries() {
		$CI =& get_instance();
		$CI->load->database();
		$times = $CI->db->query_times;
		$dbs    = array();
		$output = NULL;
		$queries = $CI->db->queries;
		
// 		echo '<pre>';
// 		print_r($queries);
// 		echo '</pre>';
		
		if (count($queries) == 0){
			$output .= "no queries\n";
		}else{
			foreach ($queries as $key=>$query){
				$output .= $query . "\n";
			}
			$took = round(doubleval($times[$key]), 3);
			$output .= "===[took:{$took}]\n\n";
		}
		
		$CI->load->helper('file');
		if ( ! write_file(APPPATH  . "/logs/queries.log.txt", $output, 'a+')){
			log_message('debug','Unable to write query the file');
		}
	}
}